//
//  LSTPopViewrRSidebarView.m
//  LSTPopView_Example
//
//  Created by LoSenTrad on 2020/4/24.
//  Copyright © 2020 490790096@qq.com. All rights reserved.
//

#import "LSTPopViewrRSidebarView.h"
#import "UIColor+LSTColor.h"
#import "UIView+LSTView.h"
#import "CCDTableViewCell.h"
#import "ZGDeviceInfo.h"
#import "NSString+BJExtension.h"
#import "UIColor+HEX.h"
#import "Masonry.h"
#import "CDModelClick.h"

@interface LSTPopViewrRSidebarView () <UITableViewDelegate,UITableViewDataSource>


/** <#.....#> */
@property (nonatomic,strong) UIButton *btn1;
/** <#.....#> */
@property (nonatomic,strong) UIButton *btn2;
/** <#.....#> */
@property (nonatomic,strong) UIButton *btn3;
/** <#.....#> */
@property (nonatomic,strong) UIButton *btn4;
/** <#.....#> */
@property (nonatomic,strong) UIButton *btn5;
/** <#.....#> */
@property (nonatomic,strong) UIButton *btn6;


/* 视图 */
@property (nonatomic,strong) UITableView *tableView;

@property (nonatomic,  strong) UIVisualEffectView *blurView;


@property (nonatomic,strong) UIView *headerView;

@property (nonatomic,strong) UILabel *lable2;

@property (nonatomic,strong) UILabel *lable3;


@end

@implementation LSTPopViewrRSidebarView


#pragma mark - ***** 初始化 *****

- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        self.layer.cornerRadius = 7;
        self.layer.masksToBounds = YES;
        self.backgroundColor = [UIColor colorWithHex:0x000000 andAlpha:1];
        [self initSubViews:frame];
    }
    return self;
}



#pragma mark - ***** setter 设置器/数据处理 *****

- (UITableView *)tableView {
    
    if (_tableView == nil) {
        
        _tableView = [[UITableView alloc] initWithFrame:self.bounds style:UITableViewStylePlain];
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.showsVerticalScrollIndicator = NO;
        
        
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.estimatedRowHeight = 44;
        _tableView.rowHeight = UITableViewAutomaticDimension;
        
        _tableView.rowHeight = UITableViewCellSeparatorStyleNone;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        
        //这行代码必须加上，可以去除tableView的多余的线，否则会影响美观
        //        _tableView.tableFooterView = [UIView new];
        ///设置table没有分割线
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
        
        [_tableView registerClass:[CCDTableViewCell class] forCellReuseIdentifier:@"CCDTableViewCell"];
        
    }
    
    return _tableView;
}

#pragma mark - ***** setupUI 界面布局 *****

- (void)initSubViews:(CGRect)frame {
    
    self.blurView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
    self.blurView.userInteractionEnabled = YES;
    self.blurView.frame = frame;
    [self addSubview:self.blurView];
    
    [self.blurView.contentView addSubview:self.tableView];
    
    self.headerView = [UIView new];
    
    self.headerView.frame = CGRectMake(0, 0, frame.size.width, 137);
    
    self.tableView.tableHeaderView = self.headerView;
    
    self.lable5 = [UILabel new];
    self.lable5.textColor = [UIColor whiteColor];
    self.lable5.font = [UIFont boldSystemFontOfSize:11];
    self.lable5.textAlignment = 1;
    
    [self.headerView addSubview:self.lable5];
    
    [self.lable5 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.offset(0);
        make.top.offset(16);
        
    }];
    
    self.lable4 = [UILabel new];
    self.lable4.textColor = [UIColor whiteColor];
    self.lable4.font = [UIFont boldSystemFontOfSize:13];
    self.lable4.textAlignment = 1;
    
  
    [self.headerView addSubview:self.lable4];
    [self.lable4 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.offset(0);
        make.top.offset(40);
        
    }];

    
    self.lable3 = [UILabel new];
    self.lable3.textColor = [UIColor whiteColor];
    self.lable3.font = [UIFont boldSystemFontOfSize:13];
    self.lable3.textAlignment = 1;
    self.lable3.text = [NSString stringWithFormat:@"%@ iOS %@",[ZGDeviceInfo currentDeviceInfo].getCurrentDevicePhoneType,[ZGDeviceInfo currentDeviceInfo].getSystemVersion];
    
    [self.headerView addSubview:self.lable3];
    [self.lable3 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.offset(0);
        make.top.offset(66);
        
    }];
    
    self.lable2 = [UILabel new];
    self.lable2.textColor = [UIColor whiteColor];
    self.lable2.font = [UIFont boldSystemFontOfSize:11];
    self.lable2.textAlignment = 1;
    self.lable2.text = [NSString stringWithFormat:@"当前时间: %@",[ZGDeviceInfo getCurrentTimes]];
    
    [self.headerView addSubview:self.lable2];
    [self.lable2 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.offset(0);
        make.top.offset(90);
        
    }];

    [NSTimer scheduledTimerWithTimeInterval:0.8 repeats:YES block:^(NSTimer * _Nonnull timer) {

        self.lable2.text = [NSString stringWithFormat:@"当前时间: %@",[ZGDeviceInfo getCurrentTimes]];
        
    }];
    
    
    
    
}

#pragma mark tableDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.titleArr.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    CCDTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CCDTableViewCell" forIndexPath:indexPath];
    
    cell.titleLab.text = self.titleArr[indexPath.row];
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    return 38;
}

- (void)setTitleArr:(NSArray *)titleArr {
    
    _titleArr = titleArr;
    
    [self.tableView reloadData];
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.row == self.titleArr.count-1) {
        
        if (self.diBlock) {
            self.diBlock(self.titleArr[indexPath.row]);
        }
        
    }
    
    [[CDModelClick sharepayManger] playFuncName:self.titleArr[indexPath.row]];
}


- (void)layoutSubviews {
    [super layoutSubviews];
    
    
}




@end
